#include <func.h>

typedef struct train_s{
    int status;
    int length;
    char buf[1000];
}train_t;

int mkDir(char *mkDirID_t, char* mkDirID, int netfd) {
    
    int orderLen = strlen(mkDirID);

    int count = 0;
    for(int i = 1; i < orderLen; i++) { 
        if(mkDirID[i] == '/') {
            count++;
        }
    }
    if(count >= 1) {
        puts("too much fir");
        return -1;
    }

    char tmp[2048];
    strcpy(tmp, mkDirID_t);

    
    if(mkDirID[0] == '/') {
        if(strcmp(mkDirID, "/..") == 0 || strcmp(mkDirID, "/.") == 0) {//分析传来的命令头部带不带‘、’，以及禁止建立“/..”和“/.”文件夹 
            puts("can't make this");
            return -1;
        }
        strcat(tmp, mkDirID);
    }
    else {
        if(strcmp(mkDirID, "..") == 0 || strcmp(mkDirID, ".") == 0) {
            puts("can't make this");
            return -1;
        }
        strcat(tmp, "/");
        strcat(tmp, mkDirID);
    }

    DIR* checkdir = opendir(tmp);
    if(checkdir != NULL) {
        puts("the dir is already build");//目录已经传递过
        return -1;
    }
    else {
        mkdir(tmp, 0775);//创建目录
    }

    return 0;
    
}

